package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",91);
        map.put("数学",92);
        map.put("英语",93);
        map.put("物理",94);
        map.put("化学",95);
        System.out.println(map);

        Set<String> keySet = map.keySet(); //将Map中所有的key以一个Set集合形式返回
        for (String key: keySet){
            System.out.println("key:" + key);
        }

        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        System.out.println(entrySet);
        for (Map.Entry<String,Integer> entry : entrySet){//遍历每一组键值对
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key + ":" + value);
        }
        map.forEach((k,v) -> System.out.println(k+":"+v));

        Collection<Integer> values = map.values();//将Map所有的value以Collection形式返回
        System.out.println(values);
        for (Integer value : values){
            System.out.println("value:" + value);
        }
        //lambda表达式的遍历
        values.forEach(value -> System.out.println("value:"+value));
    }
}
